import Vue from 'vue'
import VueRouter from 'vue-router'

// 主路由
import Find from '@/views/find'
import MyMusic from '@/views/MyMusic.vue'
import Focus from '@/views/Focus.vue'
import Download from '@/views/Download.vue'

//发现音乐路由下的子路由
import Test from '@/views/find/Test.vue'//推荐
import Rank from '@/views/find/Rank.vue'//排行榜
import SongList from '@/views/find/SongList.vue'//歌单
import Radio from '@/views/find/Radio.vue'//主播电台
import Singer from '@/views/find/Singer.vue'//歌手
import NewAlbums from '@/views/find/NewAlbums.vue'//新碟上架

Vue.use(VueRouter)
const routes = [
    {
        path: '/find',
        name: 'find',
        component: Find,
        meta: {
            title: "发现音乐"
        },
        children: [
            {
                path: '',
                redirect: '/find/test' // 设置默认进入子路由
            },
            {
                path: '/find/test',
                name: 'Test',
                component: Test,
                meta: {
                    title: "网易云音乐"
                }
            },
            {
                path: '/find/rank',
                name: 'Rank',
                component: Rank,
                meta: {
                    title: "排行榜"
                },
            }, {
                path: '/find/song-list',
                name: 'SongList',
                component: SongList,
                meta: {
                    title: "歌单"
                },
            }, {
                path: '/find/radio',
                name: 'Radio',
                component: Radio,
                meta: {
                    title: "主播电台"
                },
            }, {
                path: '/find/singer',
                name: 'Singer',
                component: Singer,
                meta: {
                    title: "歌手"
                },
            }, {
                path: '/find/new-albums',
                name: 'NewAlbums',
                component: NewAlbums,
                meta: {
                    title: "新碟上架"
                },
            },
        ],

    },
    {
        path: '/music',
        name: 'myMusic',
        component: MyMusic,
        meta: {
            title: "我的音乐"
        },
    },
    {
        path: '/focus',
        name: 'Focus',
        component: Focus,
        meta: {
            title: "关注"
        },
    },
    {
        path: '/download',
        name: 'Download',
        component: Download,
        meta: {
            title: "客户端下载"
        },
    },
    {
        path: '/',
        redirect: '/find/test'
    }
]

const router = new VueRouter({
    routes
})
router.beforeEach((to, from, next) => {
    let bool = true
    if (bool) {
        next()
    } else {
        next('/login')
    }
})
router.afterEach((to, from) => {
    console.log('全局的路由后置守卫', from);
    document.title = to.meta.title || '网易云音乐'
})
export default router